#include <pthread.h>

//锁应该由外部传入
class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex) : _mutex(mutex)
    {

    }

    ~Mutex()
    {

    }

    void lock()
    {
        pthread_mutex_lock(_mutex);    
    }

    void unlock()
    {
        pthread_mutex_unlock(_mutex);
    }


private:
    pthread_mutex_t* _mutex;
};

//lockguard：在创建对象时锁住临界区，释放对象时释放临界区
class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex) : _mutex(mutex)
    {
        _mutex.lock();
    }  

    ~LockGuard()
    {
        _mutex.unlock();
    }  
private:
    Mutex _mutex;
};

